/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SignalDialog.java
 *
 * Created on 18.12.2011., 13.46.28
 */
package aor2.gui.cpu.signals;

import aor2.components.Signal;
import aor2.cpu.blockcontrol.ConditionSignalSet;
import aor2.cpu.blockcontrol.ControlSignalSet;
import aor2.cpu.blockregisters.InstructionSignal;

import javax.swing.JComboBox;

/**
 * 
 * @author Moxi
 */
public class SignalDialog extends javax.swing.JDialog {

	private ConditionSignalSet condSet;
	private ControlSignalSet ctrlSet;

	private void addItemsCtrl(JComboBox comboBox) {

		comboBox.addItem("REGin");
		comboBox.addItem("REGout");
		comboBox.addItem("PCin");
		comboBox.addItem("PCout");
		comboBox.addItem("SPin");
		comboBox.addItem("SPout");
		// comboBox.addItem("opsel");

		// interfejs
		comboBox.addItem("mxMAR");
		comboBox.addItem("MARin");
		comboBox.addItem("MBRin");
		// comboBox.addItem("M1MBRout");
		// comboBox.addItem("M2MBRout");

		// reginstrukcija

		// comboBox.addItem("IR0in");
		// comboBox.addItem("IR1in");
		// comboBox.addItem("IR2in");
		// comboBox.addItem("IR0out");
		// comboBox.addItem("IR1out");
		// comboBox.addItem("IR2out");
		// comboBox.addItem("IR0Lout");

		// ALU
		// comboBox.addItem("Ain");
		// comboBox.addItem("Aout");
		// comboBox.addItem("Bin");
		// comboBox.addItem("Bout");

		// comboBox.addItem("ALUSHIFTout");
		// comboBox.addItem("Xin");
		// comboBox.addItem("Yin");

		// comboBox.addItem("PSWin");
		// comboBox.addItem("PSWout");
		// comboBox.addItem("ldpsw");
		// comboBox.addItem("ldpswl");
		// comboBox.addItem("clpswi");
		// comboBox.addItem("clpswt");
		// comboBox.addItem("stpswt");
		// comboBox.addItem("stpswi");

		// magistrale
		comboBox.addItem("read");
		comboBox.addItem("write");

		// comboBox.addItem("G21");
		// comboBox.addItem("G12");

		// blok prekid
		// comboBox.addItem("ldprcod");
		//
		// comboBox.addItem("stprins");
		// comboBox.addItem("stpradr");
		//
		// comboBox.addItem("clprcod");
		// comboBox.addItem("clpradr");
		// comboBox.addItem("clprirr");
		// comboBox.addItem("clprinm");
		// comboBox.addItem("clprins");
		//
		// comboBox.addItem("BRUNMSKout");
		// comboBox.addItem("BRUMSKout");
		// comboBox.addItem("IVTPout");

		// skokovi;
		// visestruki
		// comboBox.addItem("brop");
		// comboBox.addItem("braadr1");
		// comboBox.addItem("braadr2");
		// //signal skoka, nema u parsiranju
		//
		// comboBox.addItem("branch");
		// //bezuslovni
		// comboBox.addItem("bruncnd");
		// // uslovni skokovi
		// comboBox.addItem("brnotpom1");
		// comboBox.addItem("brnotpom2");
		// comboBox.addItem("bradr0");
		// comboBox.addItem("bradr1");
		// comboBox.addItem("brregdir2");
		// comboBox.addItem("brimmed2");
		// comboBox.addItem("brMOV");
		// comboBox.addItem("breql");
		//
		// comboBox.addItem("brnotprekid");
		// comboBox.addItem("brPRCOD");
		// comboBox.addItem("brPRADR");
		// comboBox.addItem("brPRINS");
		// comboBox.addItem("brPRIMM");
		// comboBox.addItem("brPRINM");
	}

	private void addItemsCond(JComboBox comboBox) {
		// comboBox.addItem("adr0");
		// comboBox.addItem("adr1");
		// comboBox.addItem("notpom1");
		// comboBox.addItem("notpom2");
		//
		// comboBox.addItem("regdir1");
		// comboBox.addItem("postinc1");
		// comboBox.addItem("predec1");
		// comboBox.addItem("index1");
		// comboBox.addItem("regind1");
		// comboBox.addItem("predecind1");
		// comboBox.addItem("postincind1");
		// comboBox.addItem("indexind1");
		//
		// comboBox.addItem("regdir2");
		// comboBox.addItem("postinc2");
		// comboBox.addItem("predec2");
		// comboBox.addItem("index2");
		// comboBox.addItem("regind2");
		// comboBox.addItem("predecind2");
		// comboBox.addItem("postincind2");
		// comboBox.addItem("indexind2");
		//
		// comboBox.addItem("immed2");
		// comboBox.addItem("eql");
		//
		// comboBox.addItem("PRINS");
		// comboBox.addItem("PRCOD");
		// comboBox.addItem("PRADR");
		// comboBox.addItem("PRINM");
		// comboBox.addItem("PRIMM");
		//
		// comboBox.addItem("MOV");
		// comboBox.addItem("SUB");
		// comboBox.addItem("OR");
		//
		// comboBox.addItem("INC");
		// comboBox.addItem("DEC");
		// comboBox.addItem("NOT");
		// comboBox.addItem("ASR");
		// comboBox.addItem("JMPIND");
		// comboBox.addItem("JSRIND");
		//
		// comboBox.addItem("BRN");
		// comboBox.addItem("BSR");
		// comboBox.addItem("BNZ");
		// comboBox.addItem("INT");

		// comboBox.addItem("RTI");
		// comboBox.addItem("RTS");
		// comboBox.addItem("INTE");
		// comboBox.addItem("INTD");
		// comboBox.addItem("TRPE");
		// comboBox.addItem("TRPD");

		comboBox.addItem("run");

		comboBox.addItem("notPrekid");
	}

	private static SignalDialog singleton = null;

	public static SignalDialog getInstance() {
		if (singleton == null)
			singleton = new SignalDialog(null, false);
		return singleton;
	}

	/** Creates new form SignalDialog */
	private SignalDialog(java.awt.Frame parent, boolean modal) {
		super(parent, modal);

		condSet = ConditionSignalSet.getInstance();
		ctrlSet = ControlSignalSet.getInstance();

		initComponents();
		addItemsCond(combo1);
		addItemsCtrl(combo1);
		addItemsCond(combo2);
		addItemsCtrl(combo2);
		addItemsCond(combo3);
		addItemsCtrl(combo3);
		addItemsCond(combo4);
		addItemsCtrl(combo4);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		scroll1 = new javax.swing.JScrollPane();
		scroll2 = new javax.swing.JScrollPane();
		scroll3 = new javax.swing.JScrollPane();
		scroll4 = new javax.swing.JScrollPane();
		combo1 = new javax.swing.JComboBox();
		combo2 = new javax.swing.JComboBox();
		combo3 = new javax.swing.JComboBox();
		combo4 = new javax.swing.JComboBox();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		combo1.addItemListener(new java.awt.event.ItemListener() {
			public void itemStateChanged(java.awt.event.ItemEvent evt) {
				combo1ItemStateChanged(evt);
			}
		});

		combo2.addItemListener(new java.awt.event.ItemListener() {
			public void itemStateChanged(java.awt.event.ItemEvent evt) {
				combo2ItemStateChanged(evt);
			}
		});

		combo3.addItemListener(new java.awt.event.ItemListener() {
			public void itemStateChanged(java.awt.event.ItemEvent evt) {
				combo3ItemStateChanged(evt);
			}
		});
		combo3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				combo3ActionPerformed(evt);
			}
		});

		combo4.addItemListener(new java.awt.event.ItemListener() {
			public void itemStateChanged(java.awt.event.ItemEvent evt) {
				combo4ItemStateChanged(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.TRAILING)
												.addComponent(
														scroll4,
														javax.swing.GroupLayout.Alignment.LEADING,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														617, Short.MAX_VALUE)
												.addComponent(
														scroll3,
														javax.swing.GroupLayout.Alignment.LEADING,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														617, Short.MAX_VALUE)
												.addComponent(
														scroll2,
														javax.swing.GroupLayout.Alignment.LEADING,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														617, Short.MAX_VALUE)
												.addComponent(
														scroll1,
														javax.swing.GroupLayout.Alignment.LEADING,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														617, Short.MAX_VALUE))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING,
												false)
												.addComponent(
														combo4,
														0,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														combo2,
														0,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														combo3,
														0,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														combo1,
														javax.swing.GroupLayout.Alignment.TRAILING,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														84,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addContainerGap()));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														combo1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														scroll1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														100,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														scroll2,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														100,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														combo2,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														combo3,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														scroll3,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														100,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														scroll4,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														100,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														combo4,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addContainerGap(
										javax.swing.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void combo3ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_combo3ActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_combo3ActionPerformed

	private void combo1ItemStateChanged(java.awt.event.ItemEvent evt) {// GEN-FIRST:event_combo1ItemStateChanged
		Signal s;
		s = ctrlSet.get(combo1.getSelectedItem().toString());
		if (s == null)
			s = condSet.get(combo1.getSelectedItem().toString());
		SignalPanel sp = new SignalPanel(s, 15);
		scroll1.setViewportView(sp);
		pack();
		repaint();
	}// GEN-LAST:event_combo1ItemStateChanged

	private void combo2ItemStateChanged(java.awt.event.ItemEvent evt) {// GEN-FIRST:event_combo2ItemStateChanged
		Signal s;
		s = ctrlSet.get(combo2.getSelectedItem().toString());
		if (s == null)
			s = condSet.get(combo2.getSelectedItem().toString());
		SignalPanel sp = new SignalPanel(s, 15);
		scroll2.setViewportView(sp);
		pack();
		repaint();
	}// GEN-LAST:event_combo2ItemStateChanged

	private void combo3ItemStateChanged(java.awt.event.ItemEvent evt) {// GEN-FIRST:event_combo3ItemStateChanged
		Signal s;
		s = ctrlSet.get(combo3.getSelectedItem().toString());
		if (s == null)
			s = condSet.get(combo3.getSelectedItem().toString());
		SignalPanel sp = new SignalPanel(s, 15);
		scroll3.setViewportView(sp);
		pack();
		repaint();
	}// GEN-LAST:event_combo3ItemStateChanged

	private void combo4ItemStateChanged(java.awt.event.ItemEvent evt) {// GEN-FIRST:event_combo4ItemStateChanged
		Signal s;
		s = ctrlSet.get(combo4.getSelectedItem().toString());
		if (s == null)
			s = condSet.get(combo4.getSelectedItem().toString());
		SignalPanel sp = new SignalPanel(s, 15);
		scroll4.setViewportView(sp);
		pack();
		repaint();
	}// GEN-LAST:event_combo4ItemStateChanged

	public SignalDialog() {
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed"
		// desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase
		 * /tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
					.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(SignalDialog.class.getName())
					.log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(SignalDialog.class.getName())
					.log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(SignalDialog.class.getName())
					.log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(SignalDialog.class.getName())
					.log(java.util.logging.Level.SEVERE, null, ex);
		}
		// </editor-fold>

		/* Create and display the dialog */
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				SignalDialog dialog = new SignalDialog(
						new javax.swing.JFrame(), true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {

					@Override
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JComboBox combo1;
	private javax.swing.JComboBox combo2;
	private javax.swing.JComboBox combo3;
	private javax.swing.JComboBox combo4;
	private javax.swing.JScrollPane scroll1;
	private javax.swing.JScrollPane scroll2;
	private javax.swing.JScrollPane scroll3;
	private javax.swing.JScrollPane scroll4;
	// End of variables declaration//GEN-END:variables
}
